﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Backend
{
    public partial class XMLGenerator : DevExpress.XtraEditors.XtraForm
    {
        private List<ZKImageInfo> sources { get; set; }
        public XMLGenerator()
        {
            InitializeComponent();
            sources = new List<ZKImageInfo>();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            using(OpenFileDialog dialog = new OpenFileDialog())
            {
                dialog.Multiselect = true;
                if(dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    dialog.FileNames.ToList().ForEach(x =>
                        {
                            ZKImageInfo info = new ZKImageInfo()
                            {
                                title = "ZKER DEMO",
                                description = "ZKER DEMO DESCRIPTION",
                                path = x,
                                content_type = ZKImageInfo.content_type_image,
                                content_path = x
                            };
                            sources.Add(info);
                        });
                }
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string xml = "";
                    sources.ForEach(x =>
                        {
                            xml += x.xmlSerialize();
                            xml += "\n";
                        });
                    string final = System.IO.File.ReadAllText("source.xml");
                    final = final.Replace("ZKER_TAG", xml);
                    System.IO.File.WriteAllText(dialog.FileName, final);
                    MessageBox.Show("Done");
                }
            }
        }
    }
}
